package com.example.demo4_sport.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;

/**
 * 配置swagger
 */
@Configuration
@EnableSwagger2//开启
public class SwaggerConfig {
    //配置Swagger的Docket的bean实例
     /*
    RequestHandlerSelectors:指定扫描的接口
    basePackage:指定扫描的包
    any:扫描所有
    none:不扫描
    withClassAnnotation:扫描类上面注解
    withMethodAnnotation:扫描方法上面注解
    */
    @Bean
    public Docket docket(){
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo()).select()
                .apis(RequestHandlerSelectors
                        .basePackage("com.example.demo4_sport.controller")).build();
    }
    //配置Swagger信息apiInfo
    private ApiInfo apiInfo(){
        //作者信息
        Contact contact = new Contact("陆俊","","lu1227jun@163.com");

        return new ApiInfo(
                "Sport的API文档",
                "",
                "v1.0",
                "",
                contact,
                "Apache 2.0",
                "http://www.apache.org/licenses/LICENSE-2.0",
                new ArrayList()
        );
    }
}